#ifndef _AVR_CPU_H_
#define _AVR_CPU_H_

#include "../../Component.h"
#include<avr/io.h>
#include<avr/interrupt.h>
#include "../../../bit/bit.h"

namespace Hardware
{
namespace Avr
{

	typedef struct AVR_CPU_CONFIG
	{
		unsigned char status;
		unsigned char generalRegisters[32];
		unsigned char extClockCallibration;
		unsigned char enableSleep : 1;
		unsigned char sleepMode : 3;
		unsigned char interruptSelect : 1;
		unsigned char interruptChangeEnable : 1;
	} AvrCpuConfig;

	typedef struct AVR_CPU_DATA
	{

	} AvrCpuData;

	class AvrCpu : public Component<AvrCpuConfig, AvrCpuData>
	{
		public :
		//enumerate the registers if needed
		enum RegisterNames
		{
			R0 = 0,
			R1 = 1,
			XLow = 26,
			XHigh = 27,
			YLow = 28,
			YHigh = 29,
			ZLow = 30,
			ZHigh = 31
		};
		enum SleepModes
		{
			IdleMode = 0x00,
			ADCNoiseReduction = 0x01,
			PowerDown = 0x02,
			PowerSave = 0x03,
			Reserved1 = 0x04,
			Reserved2 = 0x05,
			Standby = 0x06,
			ExtendedStandby = 0x07
		};
		
		AvrCpu(){}
		AvrCpu(AvrCpuConfig c){configuration=c;}
		void config()
		{	
			SREG = configuration.status;
			//set ext. clock callibration
			OSCCAL = configuration.extClockCallibration
			//now set all of the registers now
			int i = 0;
			for(i = 0; i < 32; i++)
			{
				unsigned char* data = (unsigned char*) i;
				*data = configuration.generalRegisters[i];
			}
			MCUCR = SetBit(MCUCR, SE, configuration.sleepEnable);
			//set the sleep mode
			MCUCR = SetBitGroup(MCUCR, 2, SM0,
					 configuration.sleepMode);
			//set interrupt select
			GICR = SetBit(GICR, IVSEL, 
					configuration.interruptSelect);
			//set interrupt change enable
			GICR = SetBit(GICR, IVCE,	
				configuration.interruptChangeEnable)		
		}
		void run(){}
	};
}
}




#endif
